﻿@using System.Globalization
@using OrchardPo.ViewModels
@model CultureIndexViewModel
@{
    Layout.Title = T("Localization");
}
<ol id="contentFull" style="min-height:500px">
<li class="moduleContentFull"><h2>@T("Orchard Localization")</h2>
  <p class="content">
    @T("This page allows you to view and download *.po translation files for Orchard. If you would like to help translating Orchard, please subscribe to our localization mailing-list by sending e-mail to <a href=\"mailto:join-orchard-localization@lists.outercurve.org\">join-orchard-localization@lists.outercurve.org</a> and ask for write access on this tool for your culture. You can then improve the coverage of an existing translation by modifying it directly here, or you can submit entirely new cultures that you can create from the create button below. We will not be accepting any more translations under the form of files. This online tool is the only supported way of providing translations.")
  </p><p class="content">
    @T("More information about localization can be found here: <a href=\"http://docs.orchardproject.net/Documentation/Creating-global-ready-applications\">Creating global-ready applications</a>")
  </p><p class="content">
    @T("Thanks for your contribution!")
  </p>
  <p class="content">
    @if (Model.TranslationStates.Count == 0) {
        @T("No translation is available.")
    }
    else {
    <ul>
        @foreach (var translation in Model.TranslationStates.OrderBy(c => c.Key)) {
            var culture = CultureInfo.GetCultureInfoByIetfLanguageTag(translation.Key);
            <li>
                @Html.ActionLink(
                    culture.IetfLanguageTag + " - " + culture.NativeName,
                    "Details",
                    new {path = culture.Name})
                @T("{0} translated strings out of {1}.", translation.Value.NumberOfTranslatedStrings, Model.NumberOfStringsInDefaultCulture)
            </li>
        }
    </ul>
    }
  </p>
  <div class="content">

    <h4>@T("Create a new translation:")</h4>
    <select id="downloadCulture">
    @foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures)) {
        <option value="@culture.Name">@culture.Name - @culture.NativeName</option>
    }
    </select>
    <input type="button" class="button" id="createSubmit" value="Create" />

  </div>
  @if (Model.CanUpload) {
  <div class="content">

    <h4>@T("Upload a new or updated translation file:")</h4>
    @using(Html.BeginFormAntiForgeryPost(Url.Action("Upload"), FormMethod.Post, new { enctype= "multipart/form-data"})) {
        <input type="file" class="fileupload" name="pofile" />
        <input type="submit" class="button" name="submit" value="@T("Upload")" />
    }
  </div>
  }
</li>
</ol>
<div class="clearLayout">
</div>

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
    jQuery(function ($) {
        $("#createSubmit").click(function () {
            var downloadCulture = $("#downloadCulture")[0];
            var action = "@(Url.Action("Details", new {path = "en-US"}).Replace("/en-US", "/{culture}"))"
                            .replace("{culture}", downloadCulture.options[downloadCulture.selectedIndex].value);
            window.location.assign(action);
        });
    });
</script>
